package top.rainbowecho.common.standard.database;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * @author 杨健
 * @since 2019/9/2 16:04
 */
public class PropertyConfiguration {
    private static final String DATABASE_PROPERTIES = "src/main/resources/jdbc.properties";

    private String dbDriver;    //定义驱动
    private String dbURL;        //定义URL
    private String userName;    //定义用户名
    private String password;    //定义密码
    private String prefix; // 表前缀

    public PropertyConfiguration() {
        loadConnProperties();
    }

    public String getDbDriver() {
        return dbDriver;
    }

    public String getDbURL() {
        return dbURL;
    }

    public String getUserName() {
        return userName;
    }

    public String getPassword() {
        return password;
    }

    public String getPrefix() {
        return prefix;
    }

    //从配置文件取数据库链接参数
    public void loadConnProperties(){
        Properties props = new Properties();
        try {
            props.load(new FileInputStream(DATABASE_PROPERTIES));//根据配置文件路径Conf加载配置文件
            this.dbDriver = props.getProperty("driver");//从配置文件中取得相应的参数并设置类变量
            this.dbURL = props.getProperty("url");
            this.userName = props.getProperty("username");
            this.password = props.getProperty("password");
            this.prefix = props.getProperty("prefix");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
